class Solution(object):
    def binarySearchableNumbers(self, nums):
        n = len(nums)
        left_st = [0] * n
        right_st = [0] * n
        left_st[0] = nums[0]
        right_st[n - 1] = nums[n - 1]
        for i in range(1, n):
            left_st[i] = max(left_st[i - 1], nums[i])
            right_st[n - 1 - i] = min(nums[n - 1 - i], right_st[n - i])
        ans = 0
        for i in range(n):
            left_flag = True
            right_flag = True
            if i > 0 and left_st[i - 1] > nums[i]:
                left_flag = False
            if i < n - 1 and nums[i] > right_st[i + 1]:
                right_flag = False
            if left_flag and right_flag:
                ans += 1
        return ans
